package com.Ian.homework;

import java.util.ArrayList;
import java.util.List;

public class SubStudentFunc implements InterfaceStudentFunc {
    public List<Student> getL() {
        return l;
    }

    public void setL(List<Student> l) {
        this.l = l;
    }

    private List<Student> l = new ArrayList<Student>();

    @Override
    public void add(Student st) {
                  l.add(st);
    }

    @Override
    public void del(Student st) {
        String names = st.getStrName();
        for(int i=0;i<l.size();i++) {
            if(names.equals(l.get(i).getStrName())) {
                System.out.println("找到学生正在删除");
                l.remove(i);
                System.out.println("删除成功");
            }else {
                System.out.println("删除失败未找到学生");
            }
        }
    }

    @Override
    public void sel() {
        for (Student c : l) {
            System.out.println("姓名:"+c.getStrName()+" "+"年龄:"+c.getiAge());
        }
    }

    @Override
    public void modify(Student st ,Student outSt) {
        System.out.println("要修改学生的姓名");
        String names = st.getStrName();
        for(int i=0;i<l.size();i++) {
            if(names.equals(l.get(i).getStrName())) {
                System.out.println("发现学生正在修改");
                System.out.println("请输入修改后的姓名");
                String name = outSt.getStrName();
                l.get(i).setStrName(name);
                System.out.println("请输入修改后的年龄");
                int age = outSt.getiAge();
                l.get(i).setiAge(age);
                System.out.println("修改成功");
            }else{
                System.out.println("修改失败未找到学生");
            }
        }
    }

    @Override
    public void search(Student st) {
            Student student = null;
            System.out.println("请输入你想要查询学生的姓名:");
            String name = st.getStrName();
            boolean isHave = false;
            for (Student stu : l) {
                if (stu != null) {
                    if (stu.getStrName().equals(name)) {
                        isHave = true;
                        student = stu;
                        System.out.println(student);//输出该学生的全部信息
                    }
                }
            }
            if (isHave == false) {
                System.out.println("该学生不存在!!!");
                }
        }

}
